package com.shxy.entity.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.shxy.util.converter.AbstractEnumConverter;
import com.shxy.util.converter.IEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.lang.Nullable;

/**
 * 学科枚举
 */
@Getter
@AllArgsConstructor
public enum SubjectEnum implements IEnum<String> {
    ZHEXUE("01", "哲学"),
    JINGJIXUE("02","经济学"),
    FAXUE("03","法学"),
    JIAOYUXUE("04","教育学"),
    WENXUE("05","文学"),
    LISHIXUE("06","历史学"),
    LIXUE("07","理学"),
    GONGXUE("08","工学"),
    NONGXUE("09","农学"),
    YIXUE("10","医学"),
    GUANLIXUE("11","管理学"),
    JUNSIXUE("12","军事学"),
    YISHUXUE("13","艺术学"),
    QITA("14","其他")
    ;
    private String code;
    private String name;

    /**
     * 类型转换器
     */
    public static class Converter extends AbstractEnumConverter<SubjectEnum, String> {
        public Converter() {
            super(SubjectEnum.class);
        }
    }

    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    @Nullable
    public static SubjectEnum resolve(String name) {
        for(SubjectEnum subjectEnum: SubjectEnum.values()) {
            if(name.equals(subjectEnum.getName())){
                return subjectEnum;
            }
        }
        return null;
    }
}
